package cn.anecansaitin.whimsy.common.attachment;

import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.FloatTag;
import net.minecraft.nbt.ListTag;
import net.neoforged.neoforge.common.util.INBTSerializable;

public class ImpactData implements INBTSerializable<ListTag> {
    public double x;
    public double y;
    public double z;
    public float chargedRate;
    public boolean isEnhanced;

    @Override
    public ListTag serializeNBT() {
        ListTag tags = new ListTag();
        tags.add(DoubleTag.valueOf(x));
        tags.add(DoubleTag.valueOf(y));
        tags.add(DoubleTag.valueOf(z));
        tags.add(DoubleTag.valueOf(chargedRate));
        tags.add(DoubleTag.valueOf(isEnhanced ? 1 : -1));
        return tags;
    }

    @Override
    public void deserializeNBT(ListTag nbt) {
        x = nbt.getDouble(0);
        y = nbt.getDouble(1);
        z = nbt.getDouble(2);
        chargedRate = (float) nbt.getDouble(3);
        isEnhanced = nbt.getDouble(4) > 0;
    }
}
